package com.leha.forum.lehare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leha.forum.lehare.entity.Comment;
import com.leha.forum.lehare.mapper.CommentMapper;
import com.leha.forum.lehare.service.CommentService;
import org.springframework.stereotype.Service;

import java.util.function.Supplier;

/**
* @author Administrator
* @description 针对表【comment】的数据库操作Service实现
* @createDate 2025-04-15 21:44:28
*/
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment>
    implements CommentService{

    @Override
    public IPage<Comment> getComments(Long postId, Long page, Long size, Supplier<QueryWrapper<Comment>> queryWrapperSupplier) {
        if (page <= 0) {
            throw new IllegalArgumentException("页码不能小于等于 0");
        }

        if (size <= 0) {
            throw new IllegalArgumentException("分页大小不能小于等于 0");
        }

        Page<Comment> p = new Page<>(page, size);
        return page(p, queryWrapperSupplier.get().eq("post_id", postId).orderByDesc("created_at"));
    }

    @Override
    public boolean addComment(Long userId, Long postId, Long parentId, String content) {
        return false;
    }
}




